package com.dms.model;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.dms.bean.Fee;
import com.dms.bean.Student;
import com.dms.dao.FeeDao;
import com.dms.dao.StudentDao;
import com.dms.util.DBUtil;

public class StudentModel {
        public static boolean login(Student Student) {
        	
        	DBUtil db	= new DBUtil();
        	
    		boolean val = false;
    		if (Student != null) {
    			String sql = "select stuID,password,name from student where StuID=? and password=?";
    			ResultSet rs = null;
    			try {
    				rs = db.query(sql, Student.getStuID(), Student.getPassword());
    				val = (rs != null && rs.next()) ? true : false;
    				if (val)
    					Student.setName(rs.getString("name"));
    			}
    			catch (Exception e) {
    				e.printStackTrace();
    			}
    			try {
    				db.close();
    			}
    			catch (SQLException e) {
    				e.printStackTrace();
    			}
    		}
    		return val;
    	}
        public static boolean add(String stuID, String name, String password, String dormID) {
    		boolean val = false;			
    			try {
    				Student student = new Student();
    				student.setStuID(stuID);
    				student.setName(name);
    				student.setPassword(password);
    				student.setDormID(dormID);
    				StudentDao.add(student);
    				val=true;
    			}
    			catch (Exception e) {
    				e.printStackTrace();
    			}
    			
    			return val;
    	}
}
